﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNATools.Engine2D;
using Microsoft.Xna.Framework;
using XNATools;
using XNATools.Enums;
using XNATools.Managers;

namespace TestLibrairies
{
    //Class for holding ball. Inherit from Sprite
    public class Ball : Sprite
    {
        #region Fields

        private float speed = 0.1f;
        private float rotation;
        public Vector2 Direction = Vector2.One;

        #endregion

        #region cTor(s)

        public Ball(Game game)
            : base(game, "Textures\\ball", Layer.Artwork, 1, false)
        {
        }

        #endregion

        #region Methods

        //We override Initialize because we have custom things to do
        public override void Initialize()
        {
            /* /!\ ->  Sets all properties AFTER  base.Initialize().
             * Because base.Initialize() call LoadContent() and we
             * have to LoadContent to know properties like size etc...
             */
            base.Initialize();
            rotation = 0.01f;
            Position = ScreenManager.ScreenCenter;
            RotationCenter = Center;
            Scale = new Vector2(0.1f);
            ForceTransformBounds();
        }

        //We override Update because we have custom things to while 
        //sprite update itself
        public override void Update(GameTime gameTime)
        {
            OutBorder border;
            if (IsOutOfBounds(out border, OutOfBoundsBehaviour.TextureHitsBounds))
            {
                switch (border)
                {
                    case OutBorder.Left:
                        Direction.X = 1;
                        break;
                    case OutBorder.Right:
                        Direction.X = -1;
                        break;
                    case OutBorder.Up:
                        Direction.Y = 1;
                        break;
                    case OutBorder.Down:
                        Direction.Y = -1;
                        break;
                }
            }
            Position = Position.Update(Direction * speed * gameTime.ElapsedGameTime.Milliseconds);
            Rotation += this.rotation * gameTime.ElapsedGameTime.Milliseconds;
            base.Update(gameTime);
        }

        #endregion

        #region Properties
        #endregion
    }
}
